package DBLag;

import java.sql.*;

/**
 * @author Movement optimizer
 * @version 26. oktober 2006
 */
public class DbGetMax {

	/** Creates a new instance of GetMax */
	public DbGetMax() 
	{
	}

	// getMax is for the primary key in the table
	public static int getMaxPersonId()
	{
		String query = "select max (pId) from Person";
		ResultSet results;
		int id = -1;
		try 
		{
			Statement stmt = DbConnection.getInstance().getDBcon().createStatement();
			results = stmt.executeQuery(query);
			if (results.next())
			{
				id = results.getInt(1);
			}
		}// slut try
		catch (Exception e)
		{
			System.out.println("Query exception: Error in reading maxid" + e);
		}
		return id;
	}
	
	public static int getMaxIndlaeggelsesId()
	{
		String query = "select max (iId) from Indlaeggelse";
		ResultSet results;
		int id = -1;
		try 
		{
			Statement stmt = DbConnection.getInstance().getDBcon().createStatement();
			results = stmt.executeQuery(query);
			if (results.next())
			{
				id = results.getInt(1);
			}
		}// slut try
		catch (Exception e)
		{
			System.out.println("Query exception: Error in reading maxid" + e);
		}
		return id;
	}
	
	public static int getMaxHandlingsId()
	{
		String query = "select max (hId) from Handling";
		ResultSet results;
		int id = -1;
		try 
		{
			Statement stmt = DbConnection.getInstance().getDBcon().createStatement();
			results = stmt.executeQuery(query);
			if (results.next())
			{
				id = results.getInt(1);
			}
		}// slut try
		catch (Exception e)
		{
			System.out.println("Query exception: Error in reading maxid" + e);
		}
		return id;
	}
}